component 
	extends="com.firemoss.atonement.example.contactmanager.test.ColdSpringXMLBeanFactoryTest"
	beansXml="/com/firemoss/atonement/example/contactmanager/service/config/ColdSpring.xml"
	beans="contactDao,companyDao"
{
	import com.firemoss.atonement.example.contactmanager.service.dto.*;
	
	public void function setup()
	{
		super.setup();
		variables.service = createObject( "component", "com.firemoss.atonement.example.contactmanager.service.remote.amf.ContactManagerServiceFacade" );
	}
	
	public void function service_can_list_contacts()
	{
		var uid = createUUID();
		var contactDto = new ContactDTO();
		
		contactDto.setFirstName( uid );
		
		service.saveContact( contactDTO );
		
		var list = service.listContacts();
		var last = list[ arrayLen( list )];
		assertTrue( getMetadata( last ).name eq "com.firemoss.atonement.example.contactmanager.service.dto.ContactDTO");
		assertTrue( last.getFirstName() eq uid );
	}
	
	public void function service_can_save_a_contact()
	{
		var countBefore = beans.contactDao.count();
		var uid = createUUID();
		var contactDto = new ContactDTO();
		
		contactDto.setFirstName( "Chuck" );
		
		service.saveContact( contactDTO );
		
		var countAfter = beans.contactDao.count();
		
		assertTrue( countAfter eq countBefore + 1);
	}
	
	public void function service_can_get_a_contact()
	{
		var uid = createUUID();
		var contactDto = new ContactDTO();
		
		contactDto.setFirstName( uid );
		
		var savedDto = service.saveContact( contactDTO );
		assertEquals( savedDto.getFirstName(), contactDto.getFirstName() );
		assertTrue( savedDto.getId() );
		
		var gottenDto = service.getContact( savedDto.getId() );
		assertEquals( savedDto.getId(), gottenDto.getId() );
		assertTrue( gottenDto.getId() );
		
	}
	
	public void function service_can_list_companies()
	{
		var uid = createUUID();
		var companyDto = new CompanyDTO();
		
		companyDto.setName( uid );
		
		service.saveCompany( companyDTO );
		
		var list = service.listCompanies();
		var last = list[ arrayLen( list )];
		assertTrue( getMetadata( last ).name eq "com.firemoss.atonement.example.contactmanager.service.dto.CompanyDTO");
		assertTrue( last.getName() eq uid );
	}
	
	public void function service_can_save_a_company()
	{
		var countBefore = beans.companyDao.count();
		var uid = createUUID();
		var companyDto = new CompanyDTO();
		
		companyDto.setName( uid );
		
		service.saveCompany( companyDTO );
		
		var countAfter = beans.companyDao.count();
		
		assertTrue( countAfter eq countBefore + 1);
	}
	
	public void function service_can_get_a_company()
	{
		var uid = createUUID();
		var companyDto = new CompanyDTO();
		
		companyDto.setName( uid );
		
		var savedDto = service.saveCompany( companyDTO );
		assertEquals( savedDto.getName(), companyDto.getName() );
		assertTrue( savedDto.getId() );
		
		var gottenDto = service.getCompany( savedDto.getId() );
		assertEquals( savedDto.getId(), gottenDto.getId() );
		assertTrue( gottenDto.getId() );
		
	}
	
}
